<template>
  <div>
    <section class="nav_title">
      <i>
        <a @click="back">
          <img src="../../img/i-left.png">
        </a>
      </i>
      安装客户
    </section>

    <section class="info_box">
      <i><img src="../../img/i-head.png"></i>
      <div class="info_box_left">
        <h3>{{ this.platformName }}</h3>
        <span><em><img src="../../img/i-rank.png" width="15"></em>等级：{{ this.platformLevel }}</span>
        <span><em><img src="../../img/i-info-phone.png" width="9"></em>电话：{{ this.platformPhoneNum }}</span>
      </div>
      <div class="info_box_right">
        <h3><img src="../../img/i-share.png">总安装人数</h3>
        <span>{{ this.platformInstallCount }} 人</span>
      </div>
    </section>

    <section class="share_list">
      <ul>
        <li v-for="(item,index) in detailedList" :value="item.id" :key="item.id">
          <strong>{{ index + 1 }}</strong>
          <!--<i><img src="../../img/i-head.png"></i>-->
          <div class="share_list_box">
            <span><em><img src="../../img/i-share-name.png" width="15"></em>姓  &nbsp;名：{{ item.applyName }}  (安装设备编号：{{addDeviceCode(item.deviceCode)}})</span>
            <span><em><img src="../../img/i-share-phone.png" width="10"></em>
              电  &emsp;话：
              <a :href="'tel:'+item.phoneNum"> {{ item.phoneNum }} </a>
            </span>
            <span><em><img src="../../img/i-share-date.png" width="12"></em>
              <!--申请日期：{{item.createTime}}-->
              {{ formatTime2DateTimeIsTrim(item.installationTime) }}
            </span>
          </div>
        </li>
      </ul>
    </section>
  </div>
</template>

<script>
/* eslint-disable */

  export default {
    name: 'shareInfo',
    data() {
      return {
        openid: '',
        platformName: '',
        platformPhoneNum: '',
        platformLevel: '',
        platformCount: '',
        detailedList: '',
        platformInstallCount: ''
      }
    },
    created() {
      this.initinfo();
    },
    methods: {
      initinfo: function initinfo() {
        //从缓存中获取openid
        this.openid = localStorage.getItem('openid');
        this.platformName = localStorage.getItem('platformName');
        this.platformPhoneNum = localStorage.getItem('platformPhoneNum');
        this.platformLevel = localStorage.getItem('platformLevel');
        this.platformCount = localStorage.getItem('platformCount');
        this.platformInstallCount = localStorage.getItem("platformInstallCount");

        if (!this.openid) {
          //从连接中获取或者重新请求获取数据
          this.openid = this.util.getOpenid();
        }
        let params = {
          openid: this.openid
        }
        //缓存中有数据就不用重新获取数据。
        if (this.platformPhoneNum == null) {
          //查询代理商提交数据
          this.$axios.post(this.umcons.serviceAddress.GET_PLATFORM_INFO, params)
            .then((response) => {
              this.platformName = response.data.result.platformName;
              this.platformPhoneNum = response.data.result.phoneNum;
              this.platformInstallCount = response.data.result.platformInstallCount;
              //平台商
              if (response.data.result.level == 2) {
                this.platformLevel = '运营商';
                this.platformCount = response.data.result.platformCount;
              } else if (response.data.result.level == 3) {
                this.platformLevel = '代理商';
                this.platformCount = response.data.result.agentsCount;
              }
              localStorage.setItem('openid', this.openid);
              localStorage.setItem('platformName', this.platformName);
              localStorage.setItem('platformPhoneNum', this.platformPhoneNum);
              localStorage.setItem('platformLevel', this.platformLevel);
              localStorage.setItem('platformCount', this.platformCount);
              localStorage.setItem('platformInstallCount',this.platformInstallCount);
            })
        }

        this.$axios.post(this.umcons.serviceAddress.GET_PLATFORM_INSTALL_DETAILED_INFO, params)
            .then((response) => {
              this.detailedList = response.data.result;
              //localStorage.setItem('detailedList', JSON.stringify(this.detailedList));
            })
            .catch((error) => {
              console.log(error);
            });

//        //要调整
//        if (localStorage.getItem('detailedList') == "[]") {
//          this.$axios.post(this.umcons.serviceAddress.GET_PLATFORM_INSTALL_DETAILED_INFO, params)
//            .then((response) => {
//              this.detailedList = response.data.result;
//              localStorage.setItem('detailedList', JSON.stringify(this.detailedList));
//            })
//            .catch((error) => {
//              console.log(error);
//            });
//        } else {
//          this.detailedList = JSON.parse(localStorage.getItem('detailedList'));
//        }
      },
      back: function () {  //返回上一级
        this.$router.back(-1);
      },
      formatTime2DateTimeIsTrim: function (val) {
        if (val == '' || typeof(val) == undefined || val == undefined || val == 0) {
          return '暂无数据';
        } else {
          //把时间格式转换成字符格式
          var strDate = val.toString();
          //判断第一个数是1还是2： TODO ：这个有BUG 判断当时间前面第一位数是1（strDate.charAt(0)==1 &&）和位数为13位，就是时间戳。位数超过13的时候就要报错了
          if (strDate.length == 13) {
            return formatTime2DateTime(val);
          } else {
            return strDate.replace(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/g, '$1年$2月$3日 $4:$5:$6');
          }
        }
      },
      addDeviceCode: function (val) {
        return val+1000;
      }
    }
  }
</script>

<style scoped="scoped">
  @import url("../../css/common.css");
  @import url("../../css/style.css");

</style>
